package com.mwm.paiwei.meiye;

import com.lianjiao.core.app.CoreApplication;
//import com.lzy.okhttputils.OkHttpUtils;
import com.mwm.paiwei.meiye.config.MeiYeConfig;

import org.wlf.filedownloader.FileDownloadConfiguration;
import org.wlf.filedownloader.FileDownloadConfiguration.Builder;
import org.wlf.filedownloader.FileDownloader;

/**
 * Created by wujamie on 17/4/5.
 */

public class MeiYeApplication extends CoreApplication {

    @Override
    public void onCreate() {
        super.onCreate();

//        OkHttpUtils.init(this);
        // init FileDownloader
        initFileDownloader();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();

        // release FileDownloader
        releaseFileDownloader();
    }

    // init FileDownloader
    private void initFileDownloader() {

        // 1.create FileDownloadConfiguration.Builder
        Builder builder = new Builder(this);

        // 2.config FileDownloadConfiguration.Builder
        builder.configFileDownloadDir(MeiYeConfig.FILE_PATH); // config the download path
        // builder.configFileDownloadDir("/storage/sdcard0/meiye");

        // allow 3 download tasks at the same time
        builder.configDownloadTaskSize(3);

        // config retry download times when failed
        builder.configRetryDownloadTimes(5);

        // enable debug mode
        //builder.configDebugMode(true);

        // config connect timeout
        builder.configConnectTimeout(25000); // 25s

        // 3.init FileDownloader with the configuration
        FileDownloadConfiguration configuration = builder.build(); // build FileDownloadConfiguration with the builder
        FileDownloader.init(configuration);
    }

    // release FileDownloader
    private void releaseFileDownloader() {
        FileDownloader.release();
    }
}
